//线上
const BASE_URL = "https://webapp.shenghua6.cn";
// 线下
// const BASE_URL = "https://webapp.test.shenghua6.cn";
const SDK = "https://webapp.test.shenghua6.cn/st/mini/static/js/NIM_Web_SDK_miniapp_v8.4.0.js";
const http = (opts) => {
	if (opts.url == "https://as.dun.163.com/v3/text/check") {
		// opts.data.projectId = "xcxlika";
		// opts.data.channelId = uni.getStorageSync("qudao")	
		// opts.data.appVersion = '5.5.00';
		// device_group_id: uni.getStorageSync("getSystemInfo").platfor;
		// device_model: uni.getStorageSync("getSystemInfo").mode;
	}else {
		opts.data.projectId = "xcxlika";
		opts.data.channelId = uni.getStorageSync("qudao")
		opts.data.appVersion = '5.5.00';
		device_group_id: uni.getStorageSync("getSystemInfo").platfor;
		device_model: uni.getStorageSync("getSystemInfo").mode;

	}

	return new Promise(function(resolve, reject) {
		if (uni.getStorageSync("cookie") == '') {
			var header = {
				'content-type': 'application/x-www-form-urlencoded',
				'Cookie': uni.getStorageSync("cookie"),
				'projectId': "xcxlika",
				// 'channelId': 'xcx_wx_lika',
				// 'channel_id': 'xcx_wx_lika',
				'device_group_id': uni.getStorageSync("getSystemInfo").platform,
				'device_model': uni.getStorageSync("getSystemInfo").model,
			}; //传入的opts是一个json对象
		} else {
			var header = {
				'content-type': 'application/x-www-form-urlencoded',
				'Cookie': uni.getStorageSync("cookie"),
				'projectId': "xcxlika",
				// 'channel_id': 'xcx_wx_lika',/*  */
				// 'channelId': 'xcx_wx_lika',

				'device_group_id': uni.getStorageSync("getSystemInfo").platform,
				'device_model': uni.getStorageSync("getSystemInfo").model,
			}; //传入的opts是一个json对象
		}
		var url = opts.url.indexOf("http") == 0 ? opts.url : BASE_URL + opts.url
		console.log(opts.data, "datatatatatatatatata")
		uni.request({
			url: url,
			method: opts.methods || "GET",
			data: opts.data || {},
			dataType: opts.dataType || "json",
			header: header
		}).then((response) => {
			let [error, res] = response
			if (res.data.code == 30001) {

				console.log('登陆失效跳转登录', url)
				
				
				
				// uni.redirectTo({
				// 	url: '/pages/login/wxlogin'
				// })
				
				
				// 清空本地消息缓存
								getApp().globalData = {
									sessions: [],
									set: 1,
									huihua: []
								}
								uni.redirectTo({
									url: "/pages/login/wxlogin",
								});
								//清除本地登录状态
								// uni.clearStorage();
								//IM实例销毁
								// 清除本地cookie
								uni.removeStorage({key: 'cookie'});
								Vue.prototype.$NIM.disconnect();
				
				
				
			}
			resolve(res)
		}).catch(error => {
			let [err, res] = error
			reject(err)
		})
	})
}


export default {
	http,
	BASE_URL,
	SDK
}
